#define _CRT_SECURE_NO_WARNINGS 1
#include"List.h"
LTNode* BuyListNode(LTDataType x)
{
	LTNode* New = (LTNode*)malloc(sizeof(LTNode));
	if (New == NULL)
	{
		perror("malloc");
		exit(-1);
	}
	New->next = NULL;
	New->prev = NULL;
	New->data = x;
	return New;
}
LTNode* LTInit()
{
	LTNode* phead=BuyListNode(-1);
	phead->next = phead;
	phead->prev = phead;
	return phead;
}
void LTDestroy(LTNode* phead)
{
	assert(phead);
	LTNode* cur = phead->next;
	while (cur != phead)
	{
		LTNode* next = cur->next;
		free(cur);
		cur = next;
	}
	free(phead);
}
void LTPrint(LTNode* phead)
{
	assert(phead);
	LTNode*cur = phead->next;
	printf("<=phead=>");
	while (cur!=phead)
	{
		printf("%d<=>", cur->data);
		cur = cur->next;
	}
	puts("");
}
bool LTEmpty(LTNode* phead)
{
	assert(phead);
	return phead == phead->next;
}
void LTInsert(LTNode* pos, LTDataType x)
{
	assert(pos);
	LTNode* prev = pos->prev;
	LTNode* new = BuyListNode(x);
	prev->next = new;
	new->prev = prev;
	new->next = pos;
	pos->prev = new;
}
void LTErase(LTNode* pos)
{
	assert(pos);
	LTNode* prev = pos->prev;
	LTNode* next = pos->next;
	prev->next = next;
	next->prev = prev;
	free(pos);
}
void LTPushBack(LTNode* phead, LTDataType x)
{
	assert(phead);
	LTInsert(phead,x);
}
void LTPopBack(LTNode* phead)
{
	assert(phead);
	LTErase(phead->prev);
}
void LTPushFront(LTNode* phead, LTDataType x)
{
	assert(phead);
	LTInsert(phead->next, x);
}
void LTPopFront(LTNode* phead)
{
	assert(phead);
	LTErase(phead->next);
}
LTNode* LTFind(LTNode* phead, LTDataType x)
{
	assert(phead);
	LTNode* find = phead->next;
	while (find != phead)
	{
		if (phead->data == x)
			return find;
		find = find->next;
	}
	return NULL;
}

	